import http from '@/server/request.js';
import * as Utils from '@/utils/index.js';
import * as Auth from '@/utils/auth';

let header = { 'content-type': 'application/json' };
let token_type = 'bearer';
let acc_token = '';
let acc_token_header_key = 'Authorization';

/**
 * 获取视频
 * @param {String} videoId 视频videoId
 */
export const videoUrl = async (videoId) => {
  const data = await http.request({
    baseUrl: 'https://gateway.wxls.pro',
    url: '/admin/apiPass/video/details?videoId=' + videoId,
    method: 'GET',
  });
  if (!data.data.success) {
    uni.showToast({
      title: data.data.message || '获取视频失败',
      duration: 2000,
      icon: 'none',
    });
    return Promise.reject(new Error(data.data.message || '获取视频失败'));
  }
  return data;
};

// 获取阿里云音视频播放时所需的播放凭证
export const videoPlayauth = async (param) => {
  const data = await http.request({
    baseUrl: 'https://api.wxls.pro/cms',
    url: '/pass/video/video/play/auth',
    method: 'GET',
    data: param,
  });
  if (!data.data.success) {
    uni.showToast({
      title: data.data.message || '获取音视频播放时所需的播放凭证失败',
      duration: 2000,
      icon: 'none',
    });
    return Promise.reject(
      new Error(data.data.message || '获取音视频播放时所需的播放凭证失败'),
    );
  }
  return data;
};
